<!doctype html>
<html>
<head>
  <title>element script</title>
  <script src="../../polymer.js"></script>
  <script src="../../tools/test/htmltest.js"></script>
  <script src="../../node_modules/chai/chai.js"></script>
  <script src="element-script/elements.js"></script>
</head>
<body>
  <x-foo></x-foo>  
  <hr>
  
  <x-bar></x-bar>
  <hr>
  
  <x-zot></x-zot>
  <hr>

  <x-baz></x-baz>
  <hr>
  
  <x-qux></x-qux>
  <hr>

  <x-quux></x-quux>
  <hr

  <!-- preloaded external script -->
  <polymer-element name="x-foo">
    <template>
      Hello Light World
    </template>
  </polymer-element>
  
  <!-- external script with super() -->
  <polymer-element name="x-bar" extends="x-foo">
    <template>
      Hello Lighter World [<shadow></shadow>]
    </template>
  </polymer-element>

  <!-- no script -->
  <polymer-element name="x-zot" extends="x-foo">
    <template>
      Hello Lighter World [<shadow></shadow>]
    </template>
  </polymer-element>

  <!-- inline script -->
  <polymer-element name="x-baz" extends="x-zot">
    <script>
      Polymer('x-baz', {
        ready: function() {
          this.style.padding = '4px';
          this.style.backgroundColor = 'tomato';
          this.super();
        }
      });
    </script>
  </polymer-element>
  
  <!-- inline script before polymer-element -->
  <script>
    Polymer('x-qux', {
      ready: function() {
        this.style.padding = '4px';
        this.style.backgroundColor = 'green';
        this.super();
      }
    });
  </script>
  <polymer-element name="x-qux" extends="x-zot"></polymer-element>

  <!-- inline external script -->
  <polymer-element name="x-quux" extends="x-zot">
    <script src="element-script/x-quux.js"></script>
  </polymer-element>
  
  <script>
    var assert = chai.assert;
    document.addEventListener('WebComponentsReady', function() {
      var foo = document.querySelector('x-foo');
      assert.equal(getComputedStyle(foo).color, 'rgb(0, 0, 255)');
      //
      var bar = document.querySelector('x-bar');
      assert.equal(getComputedStyle(bar).color, 'rgb(0, 0, 255)');
      assert.equal(getComputedStyle(bar).backgroundColor, 'rgb(255, 165, 0)');
      //
      var zot = document.querySelector('x-zot');
      assert.equal(getComputedStyle(zot).color, 'rgb(0, 0, 255)');
      //
      var baz = document.querySelector('x-baz');
      assert.equal(getComputedStyle(baz).color, 'rgb(0, 0, 255)');
      assert.equal(getComputedStyle(baz).backgroundColor, 'rgb(255, 99, 71)');
      //
      var qux = document.querySelector('x-qux');
      assert.equal(getComputedStyle(qux).color, 'rgb(0, 0, 255)');
      assert.equal(getComputedStyle(qux).backgroundColor, 'rgb(0, 128, 0)');
      //
      var quux = document.querySelector('x-quux');
      assert.equal(getComputedStyle(quux).color, 'rgb(0, 0, 255)');
      assert.equal(getComputedStyle(quux).fontSize, '24px');
      done();
    });
  </script>
  
</body>
</html>